package com.shop.shard.controller.rest.order;

import com.shop.shard.common.*;
import com.shop.shard.controller.assembler.order.OrderItemAssembler;
import com.shop.shard.controller.command.order.OrderItemCreateCommand;
import com.shop.shard.controller.command.order.OrderItemUpdateCommand;
import com.shop.shard.entity.order.OrderItem;
import com.shop.shard.vo.order.OrderItemVO;
import com.shop.shard.service.order.OrderItemService;
import com.shop.shard.manager.order.OrderItemManager;
import com.shop.shard.mapper.order.OrderItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * @Description: 代码生成器自动生成
 * @author:
 * @Createed Date: 2019-8-16 10:06:57
 * @ModificationHistory: Who  When  What
 * ---------     -------------   --------------------------------------
 **/
@RestController
@RequestMapping("api/v1/order/orderItem")
@Api(value = "orderItemService", description = "orderItem相关AIP")
public class OrderItemRest  {

    @Autowired
    private OrderItemMapper orderItemMapper;
    @Autowired
    private OrderItemService orderItemService;
    @Autowired
    private OrderItemManager orderItemManager;


    @PostMapping("add")
    @ApiOperation(value = "add OrderItem ", notes = "xxx")
    public InvokeResult add(@RequestBody @Valid OrderItemCreateCommand command) {
        OrderItem entity = OrderItemAssembler.toOrderItem(command);
        orderItemService.addEntity(entity);
        return InvokeResult.success();
    }

    /**
    * delect OrderItem by id
    * @return
    */
    @PostMapping("delete")
    @ApiOperation(value = "delect OrderItem by id", notes = "xxx")
    public InvokeResult delete(Long id){
        orderItemService.delete(id);
        return InvokeResult.success();
    }


    @PostMapping("update")
    @ApiOperation(value = "update OrderItem by id", notes = "xxx")
    public InvokeResult update(@RequestBody @Valid OrderItemUpdateCommand command) {
        OrderItem entity = OrderItemAssembler.toOrderItem(command);
        orderItemService.updateEntity(entity);
        return InvokeResult.success();
    }

    @GetMapping("detail")
    @ApiOperation(value = "get OrderItem detail by id", notes = "xxx")
    public InvokeResult detail(@RequestParam() Long id) {
        OrderItemVO vo = orderItemManager.selectDetailVoById(id);
        return InvokeResult.success(vo);
    }

    @GetMapping("page")
    @ApiOperation(value = "get OrderItem page ", notes = "xxx")
    public IPage<OrderItemVO> page(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10")Integer pageSize){
        Page page = new Page(pageNum,pageSize);
        Map<String,Object> map=new HashMap<>(4);
        IPage<OrderItemVO> iPage=  orderItemManager.getPage(page,map);
        return iPage;
    }
}
